package com.wuxin.ssm.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuxin.ssm.entity.ProductInfo;
import com.wuxin.ssm.entity.ProductInfoExample;
import com.wuxin.ssm.mapper.ProductInfoMapper;
import com.wuxin.ssm.service.ProductInfoService;
import com.wuxin.ssm.vo.ForeProductInfoVo;
import com.wuxin.ssm.vo.ProductInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: untitled
 * @ClassName ProductInfoService
 * @description:
 * @author: 李尧坤
 * @create: 2024−12-03 19:25
 * @Version 1.0
 **/
@Service
public class ProductInfoServiceImp implements ProductInfoService {

    @Autowired
    private ProductInfoMapper productInfoMapper;
    @Override
    public PageInfo splitPage(Integer page, int pageSize) {
        //对象是空的
        ProductInfoExample example = new ProductInfoExample();
        //使用分页 必须先设置这个方法
        PageHelper.startPage(page,pageSize);
        //查询所有数据
        List<ProductInfo> productInfoList = productInfoMapper.selectByExample(example);
        //将集合交给分页类
        PageInfo<ProductInfo> pageInfo= new PageInfo<ProductInfo>(productInfoList);

        return pageInfo;
    }

    @Override
    public PageInfo chaxun(Integer page, int pageSize, ProductInfoVo myform) {

        //使用分页 必须先设置这个方法
        PageHelper.startPage(page,pageSize);

        List<ProductInfo> productInfoList = productInfoMapper.selectCondition(myform);

        //将集合交给分页类
        PageInfo<ProductInfo> pageInfo= new PageInfo<ProductInfo>(productInfoList);

        return pageInfo;
    }

    @Override
    public void batchDel(Integer[] ids) {
        productInfoMapper.batchDel(ids);
    }

    @Override
    public ProductInfo findProductById(Integer pid) {
        ProductInfo productInfo = productInfoMapper.selectByPrimaryKey(pid);
        return productInfo;
    }

    @Override
    public void addProductInfo(ProductInfo productInfo) {

        productInfoMapper.insert(productInfo);
    }

    @Override
    public void deleteById(Integer pid) {
        productInfoMapper.deleteByPrimaryKey(pid);
    }

    @Override
    public void updateproduct(ProductInfo productInfo) {
        productInfoMapper.updateByPrimaryKey(productInfo);
    }

    @Override
    public PageInfo Forechaxun(Integer page, int pageSize, ForeProductInfoVo foreProductInfoVo) {
        //使用分页 必须先设置这个方法
        PageHelper.startPage(page,pageSize);

        List<ProductInfo> productInfoList = productInfoMapper.foreselectCondition(foreProductInfoVo);

        System.out.println(foreProductInfoVo.getTypeid());
        System.out.println(foreProductInfoVo.getPname());
        System.out.println(foreProductInfoVo.getPage());
        System.out.println(foreProductInfoVo.getPcontent());
        System.out.println(foreProductInfoVo.getLprice());
        System.out.println(foreProductInfoVo.getHprice());


        //将集合交给分页类
        PageInfo<ProductInfo> pageInfo= new PageInfo<ProductInfo>(productInfoList);

        return pageInfo;
    }


}
